﻿using System;
using System.Collections.Generic;
using System.Linq;

using Fuse8.DomainFramework.Common;

namespace Fuse8.ContentManagementFramework.SystemFacade.Extensions
{
    public static class EnumerableExtensions
    {
        public static string ToPlainString(this IEnumerable<string> source)
        {
            return source.ToPlainString(",");
        }
        
        public static string ToPlainString(this IEnumerable<string> source, string separator)
        {
            Guard.ArgumentNotNull(source, "source");

            return source
                .AsParallel()
                .Aggregate(
                    (working, next) =>
                    {
                        return string.Format("{0}{1}{2}", working, separator, next);
                    });
        }
    }
}
